#ifndef MY_HEADER_H
#define MY_HEADER_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <assert.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <dirent.h>
#include <syslog.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <signal.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <strings.h>
#include <sys/epoll.h>
#include <shadow.h>
#include <crypt.h>
#include <sys/sendfile.h>

// 检查命令行参数数量是否符合预期
#define ARGS_CHECK(argc, expected) \
    do { \
        if ((argc) != (expected)) { \
            fprintf(stderr, "args error!\n"); \
            exit(1); \
        } \
    } while (0)

// 检查返回值是否是错误标记,若是则打印msg和错误信息
#define ERROR_CHECK(ret, error_flag, msg) \
    do { \
        if ((ret) == (error_flag)) { \
            perror(msg); \
            exit(1); \
        } \
    } while (0)

// 检查基于thread操作的各个函数的返回值
#define THREAD_ERROR_CHECK(ret, msg) { \
    if(ret != 0) { \
        fprintf(stderr, "%s:%s \n", msg, strerror(ret)); \
    } \
}

#define NETDISK_LOG_INFO(net_fd, clientAddr) \
    do { \
        syslog(LOG_INFO, "1 client connected, fd = %d, ip = %s, port = %hu\n", net_fd, inet_ntoa(clientAddr.sin_addr), ntohs(clientAddr.sin_port)); \
    } while (0)
    

#define NETDISK_LOG_ERR(ret, err) { \
    if(ret == err) { \
        syslog(LOG_ERR, "an error occurred in %s:%s:%d\n", __FILE__, __FUNCTION__, __LINE__); \
    } \
}
#endif
